﻿using System;
using System.Collections.Generic;
using System.Text;

namespace TwiSQL
{
    public class TextUtil
    {
        public static string HtmlEntityEncode(string unicodeText)
        {

            int unicodeVal;
            string encoded = "";

            foreach (char c in unicodeText)
            {

                unicodeVal = c;

                if ((c >= 49) && (c <= 122))
                {

                    // in 'ascii' range x30 to x7a which is 0-9A-Za-z plus some punctuation

                    encoded += c;	// leave as-is

                }
                else
                { // outside 'ascii' range - encode

                    encoded += string.Concat("&#",

                        unicodeVal.ToString(System.Globalization.NumberFormatInfo.InvariantInfo), ";");

                }

            }

            return encoded;

        }
    }
}
